<template>
	<view>
		<view class="content">
			<view style="height: 240rpx;margin-bottom: 20rpx;">
				<swiper class="swiper-box" @change="change" style="height: 200rpx;">
					<swiper-item v-for="(item ,index) in info" :key="index">
						<image style="width: 100%; height: 100%;" :src="item.content"></image>
					</swiper-item>
				</swiper>
				<view class="dot-content">
					<view v-for="(item ,index) in info" :key="index" class="swiper-dot" :class="current_index === index? 'active':''">
					</view>
				</view>
			</view>
			<view class="options-list" v-for="(items, index) in menuList" :key="index" @click="jumpLink(items.url)">
				<view class="options-items">
					<view class="options-image">
						<image style="width: 100%; height: 100%;" :src="items.image"></image>
					</view>
					<view class="options-name">
						{{ items.name }}
					</view>
				</view>
				<view class="option-right">
					<image style="width: 100%; height: 100%;" :src="icons.right"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				info: [{
					content: '/static/images/banner@3x.png'
				}, {
					content: '/static/images/banner@3x.png'
				}, {
					content: '/static/images/banner@3x.png'
				}],
				current_index: 0,
				menuList: [{
					name: "排餐管理",
					image: "/static/images/icon_pcgl@3x.png",
					url: "/pages/backstage/supplier/platoon"
				}, {
					name: "备货管理",
					image: "/static/images/icon_bhgl@3x.png",
					url: "/pages/backstage/supplier/stock"
				}, {
					name: "设备查询",
					image: "/static/images/icon_sbcx@3x.png",
					url: ""
				}],
				icons: {
					right: "/static/images/icons/icon_next@3x.png"
				}
			}
		},
		created() {
			let key = this.getUrlKey('key')
			if (key) {
				this.getMess(key);
			} else {
				const _this = this;
				let token = "";
				uni.getStorage({
					key: 'uerInfo',
					success: function(res) {
						_this.keepLogin(res.data.token)
					}
				});
			}
		},
		methods: {
			keepLogin(token) {
				const path = {
					app: "wxadmin",
					api: "api_wxadmin_admin_keepLogin",
					version: "1.0",
					type: 2,
					data: {
						token: token
					}
				}
				const _this = this;
				_this.sendSock(path, function(res) {
					_this.getSock(res.data)
				})
			},
			getMess(key) {
				const path = {
					app: "wxadmin",
					api: "api_wxadmin_admin_login",
					version: "1.0",
					type: "1",
					data: {
						key: key
					}
				}
				const _this = this;
				_this.sendSock(path, function(res) {
					_this.getSock(res.data)
				})
			},
			change(e) {
				this.current_index = e.detail.current;
			},
			jumpLink(link) {
				if (link) {
					const _this = this;
					uni.navigateTo({
						url: link + '?' + _this.version
					})
				}
			},
			getSock(res) {
				console.log('res', res)
				if (res !== '{"type":"ping"}') {
					const resj = JSON.parse(res);
					if (resj.code === -1) {
						uni.showToast({
							icon: "none",
							title: resj.message,
							duration: 2000
						});
					} else if (resj.code === 403) {
						const key = this.getUrlKey('key')
						this.getMess(key);

					} else {
						if (resj.api === "api_wxadmin_admin_login") {
							this.$store.commit('login', resj.data);
							this.temporary()
						} else if (resj.api === "api_wxadmin_admin_keepLogin") {
							this.temporary()
						}
					}
				}
			}
		}
	}
</script>

<style>
	.content {
		padding: 30rpx;
	}

	.options-list {
		background: rgba(255, 255, 255, 1);
		box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(0, 0, 0, 0.1);
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 120rpx;
		padding: 0 20rpx;
		margin-bottom: 40rpx;
	}

	.options-items {
		display: flex;
		align-items: center;
	}

	.options-image {
		width: 72rpx;
		height: 72rpx;
	}

	.options-name {
		margin-left: 10rpx;
	}

	.option-right {
		width: 16rpx;
		height: 30rpx;
		display: flex;
		align-items: center;
	}
</style>
